#include "force_generators.h"

void GravityForce::update(SpringBody *b, double dt )
{
	for(size_t i=0; i<b->particles.size(); i++)
	{
		Particle *p = b->particles[i];
		Vec2f forceDir = (p->pos - gravitySourcePos);
		real len2 = length_2( forceDir );
		Vec2f forceNormal = normalize(forceDir);

		p->forceAccum += (real)-0.01 * forceNormal / (len2);
	}

}

GravityForce::GravityForce()
{
	gravitySourcePos.is(0,0);
}

GravityForce::GravityForce( real x, real y )
{
	gravitySourcePos.is(x,y);
}


ThrustGenerator::ThrustGenerator()
{
	timeLeft = 0.0;
}

void ThrustGenerator::update( SpringBody *b, double dt )
{
	if( timeLeft > 0.0 )
	{
		timeLeft -= (real) dt;
		b->addForce( thrustDir );
	}
}
